<?php

/**
 * 影院订单列表
 */
class Action
{
    private $per_page = 100;

    /**
     * 显示订单列表
     */
    public function index() {
        $page = Request::Get('page_no', 1);
        $status = Request::getParam('status', 1);
        $progress = Request::getParam('progress', '-1');
        $task_user_id = Request::getParam('task_user_id', '-1');
        $type = Request::getParam('type', 5);
        $search_filter = Request::getParam('search_filter', array());
        $search_attach_filter = Request::getParam('search_attach_filter', array());
        $is_excel = Request::getParam('is_excel', 0);
        $store_type = Request::getParam('store_type', '100');

        // 拼装搜索条件
        $is_empty = 0;
        $filter = array(
            'store_id' => array(),
        );

        //获取当前用户可看的区域
        $role_id = user_helper::get_admin_role_id();
        if (!user_helper::is_all_can_show($role_id)) {
            $filter['store_id'] = store_helper::get_store_ids_by_admin_user(array(100));
            if (!$filter['store_id']) {
                $filter['store_id'] = -1;
            }
        }

        if ($search_attach_filter) {
            //筛选影院名称
            if ($search_attach_filter['cinema_name']) {
                $ids = cinema_helper::get_cinema_ids_by_name($search_attach_filter['cinema_name']);
                if ($ids) {
                    if (!$filter['store_id']) {
                        $filter['store_id'] = $ids;
                    } else {
                        $filter['store_id'] = array_intersect($filter['store_id'], $ids);
                    }
                } else {
                    $filter['store_id'] = -1;
                }
            }
            //筛选合伙人
            if ($search_attach_filter['agency_name']) {
                $ids = cinema_helper::get_cinema_ids_by_agency_name($search_attach_filter['agency_name']);
                if ($ids) {
                    if (!$filter['store_id']) {
                        $filter['store_id'] = $ids;
                    } else {
                        $filter['store_id'] = array_intersect($filter['store_id'], $ids);
                    }
                } else {
                    $filter['store_id'] = -1;
                }
            }
            //影院销售
            if ($search_attach_filter['cinema_assistant_name']) {
                $province_list = cinema_helper::get_cinema_assistant_province_by_name($search_attach_filter['cinema_assistant_name']);
            }

            //获取省市
            if ($search_attach_filter['province_id']) {
                if ($province_list) {  // 如果是影院销售和省市选择都存在,只调用省市数据
                    $ids = store_helper::get_store_ids_by_area($province_list, $store_type);
                } else {
                    $ids = store_helper::get_store_ids_by_area($search_attach_filter['province_id'], $search_attach_filter['city_id'], $search_attach_filter['district_id'], $store_type);
                }

                if ($ids) {
                    if (!$filter['store_id']) {
                        $filter['store_id'] = $ids;
                    } else {
                        $filter['store_id'] = array_intersect($filter['store_id'], $ids);
                    }
                } else {
                    $filter['store_id'] = -1;
                }
            }
        }

        if (isset($search_filter['id']) && $search_filter['id']) {
            $filter['id'] = $search_filter['id'];
        }

        if ($store_type != -1) {
            $order_branch_ids = _model('order_branch')->getFields('order_id', array('store_type' => $store_type), 'ORDER BY `order_id` DESC');
            $filter['id'] = $order_branch_ids;
        }

        if (isset($search_filter['progress']) && $search_filter['progress'] && $search_filter['progress'] != '-1') {
            $filter['progress'] = $search_filter['progress'];
        }
        if (isset($search_filter['order_code']) && $search_filter['order_code']) {
            $decoded_id = order_helper::order_id_decode($search_filter['order_code']);
            if (is_numeric($decoded_id)) {
                $filter['id'] = $decoded_id;
            }
        }

        // 有效的
        $filter['is_enable'] = 1;

        // 下单时间
        if (isset($search_filter['start_date_add']) && $search_filter['start_date_add']) {
            $filter['add_time >='] = $search_filter['start_date_add'] . ' 00:00:00';
        }
        if (isset($search_filter['end_date_add']) && $search_filter['end_date_add']) {
            $filter['add_time <='] = $search_filter['end_date_add'] . ' 23:59:59';
        }

        // 到货时间
        if (isset($search_filter['start_date_receiver']) && $search_filter['start_date_receiver']) {
            $filter['receiver_time >='] = $search_filter['start_date_receiver'] . ' 00:00:00';
        }
        if (isset($search_filter['end_date_receiver']) && $search_filter['end_date_receiver']) {
            $filter['receiver_time <='] = $search_filter['end_date_receiver'] . ' 23:59:59';
        }

        // 支付时间
        if (isset($search_filter['start_date_pay']) && $search_filter['start_date_pay']) {
            $filter['pay_time >='] = $search_filter['start_date_pay'] . ' 00:00:00';
        }
        if (isset($search_filter['end_date_pay']) && $search_filter['end_date_pay']) {
            $filter['pay_time <='] = $search_filter['end_date_pay'] . ' 23:59:59';
        }

        if (isset($progress) && $progress != '-1') {
            $filter['progress'] = intval($progress);
        }

        if ($status != -1) {
            $filter['status'] = $status;
        }

        // 代理
        if ($task_user_id == 1) {
            $filter['task_user_id > '] = 0;
        } else {
            if ($task_user_id == 0) {
                $filter['task_user_id'] = 0;
            }
        }

        if ($progress != '-1' || $status == 0) {
            $filter['status'] = $status;
        } else {
            $filter['1'] = 1;
        }
        // added type filter by ninghx 用来区分总部订单、经销商订单还是影院订单
        if (isset($type) && $type) {
            $filter['type'] = $type;
        }

        $order_list = array();
        if (!$is_empty) {
            $order_count = _model('order')->getTotal(enable_filter($filter));
            if ($order_count) {
                $pager = new Pager($this->per_page);
                if ($pager->generate($order_count)) {
                    Response::assign('pager', $pager);
                }
                $order_by = ' ORDER BY `id` DESC ';
                if (!$is_excel) {
                    $order_by .= $pager->getLimit($page);
                }
                $order_list = _model('order')->getList(enable_filter($filter), $order_by);

                foreach ($order_list as $k => $v) {
                    $order_list[$k]['order_relation'] = _model('order_relation')->getList(array(
                        'order_id' => $v['id'],
                        'status' => 1
                    ));
                    // 送货单明细
                    $order_list[$k]['order_delivery_note'] = order_helper::get_order_delivery_note_info_by_order_id($v['id']);
                    // 合伙人
                    $order_list[$k]['dealer_info'] = user_helper::get_user_info($v['agency_id']);
                }

                if ($is_excel == 1) {
                    $this->export_excel($order_list);
                }
                if ($is_excel == 2) {
                    $this->export_excel2($order_list);
                }
                Response::assign('count', $order_count);
            }
        }

        $express_list = _model('express')->getList(array('status' => 1));

        Response::assign('role_id', $role_id);
        Response::assign('express_list', $express_list);
        Response::assign('order_list', $order_list);
        Response::assign('status', $status);
        Response::assign('progress', $progress);
        Response::assign('task_user_id', $task_user_id);

        Response::assign('type', $type);
        Response::assign('store_type', $store_type);
        Response::assign('search_filter', $search_filter);
        Response::assign('search_attach_filter', $search_attach_filter);
        Response::assign('order_count', $order_count);

        Response::display('admin/cinema_order_list.html');
    }


    /**
     * 用户订单表
     */
    public function export_excel($list = array()) {
        //初始化excel对象
        $objPHPExcel = new PHPExcel();
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        //设置当前的sheet索引，用于后续的内容操纵
        $objPHPExcel->setActiveSheetIndex(0);
        $objActSheet = $objPHPExcel->getActiveSheet();

        // 哪几列
        $col_arr = array();
        // 第一排的标题
        $col_title_arr = array(
            '序号',
            '订单编号',
            '总数量',
            '总价',
            '商家信息',
            '杯型信息(杯)',
            '订单类型',
            '订单状态',
            '支付方式',
            '影院名称',
            '影院id',
            '省',
            '市',
            '区',
            '合伙人',
            '合伙人手机'
        );

        $col_content_arr = array(
            'number',
            'order_id',
            'sum',
            'price',
            'store_info',
            'cup_info',
            'order_type',
            'progress',
            'pay_type',
            'cinema_name',
            'cinema_id',
            'province',
            'city',
            'county',
            'agency',
            'agency_mobile'
        );

        //获取电影商品列表
        $goods_id = goods_helper::get_goods_by_channel_id(array(1, 3));
        if ($goods_id) {
            $goods_id = array_unique($goods_id);
        }
        $goods_info = _model('goods')->getList(array('id' => $goods_id, 'is_sale' => 1, 'status' => 1));
        $goods_detail = array();
        foreach ($col_title_arr as $k => $v) {
            $abc = cinema_helper::excel_column_encode($k);
            array_push($col_arr, $abc);
        }
        $attach_row = array('-单价(元)', '-实际需支付(元)', '-数量');
        foreach ($goods_info as $k => $v) {
            $one_goods_detail = array();
            foreach ($attach_row as $k1 => $v1) {
                array_push($col_title_arr, $v['title'] . $v1);
                $abc = cinema_helper::excel_column_encode(count($col_arr));
                array_push($col_arr, $abc);

                if ($one_goods_detail) {
                    array_push($one_goods_detail, array($abc));
                } else {
                    $one_goods_detail = array($abc);
                }

                array_push($col_content_arr, $abc);
            }
            $goods_detail[$v['id']] = $one_goods_detail;
        }


        // 设置文档属性
        foreach ($col_arr as $k => $v) {
            //设置4个列的宽度
            if (in_array($v, array('A'))) {
                $objActSheet->getColumnDimension($v)->setWidth(8);
            } else {
                $objActSheet->getColumnDimension($v)->setWidth(20);
            }
            //设置单位格内容A1,B1,C1,D1
            $objActSheet->setCellValue($v . "1", $col_title_arr[$k]);
            //格式化数字为字符串，避免导致数字默认右对齐单元格
            //            $objActSheet->getStyle($v)->getNumberFormat()->setFormatCode("@");
            //设置自动换行
            $objActSheet->getStyle($v)->getAlignment()->setWrapText(true);
        }

        // 填充单元格
        $key = 2;
        foreach ($list as $k => $v) {

            $order_type_list = order_config::$order_type;
            $cup_name_list = cup_config::$cup_type;
            $pay_type_list = order_config::$pay_type;
            $order_progress = order_config::$store_progress;
            $store_info = store_helper::get_store($v['store_id']);
            $zzb_info = array();

            if ($store_info['zzb_id'] > 0) {
                $zzb_info = cinema_helper::get_cinema_info_by_id($store_info['zzb_id']);
            }

            // 先将合并的信息填入excl
            foreach ($col_arr as $k2 => $v2) {
                $place = $v2 . $key;
                $col_content = $col_content_arr[$k2];
                $value = '0';

                if ($col_content == 'order_id') {
                    $value = order_helper::order_id_encode($v['id']);
                }
                if ($col_content == 'price') {
                    $value = $v['price'];
                }
                if ($col_content == 'pay_type') {
                    $value = $pay_type_list[$v['pay_type']];
                }
                if ($col_content == 'sum') {
                    //订单总商品数
                    $value = $v['goods_num'];
                }
                if ($col_content == 'store_info') {
                    // 商家信息
                    $user_info = user_helper::get_user_info($v['user_id']);
                    $value = "收货人：" . $user_info['realname'] . "\r手机号码：" . $user_info['mobile'];
                }
                if ($col_content == 'cup_info') {
                    // 杯型信息
                    $cup_list_info = cup_helper::get_order_cup_data($v['id']);
                    if (!$cup_list_info) {
                        $value = '0';
                    } else {
                        $value = '';
                        foreach ($cup_list_info as $cup_k => $cup_v) {
                            $value .= $cup_name_list[$cup_v['cup_type']] . '：' . $cup_v['true_cup_num'] . "\r";
                        }
                    }
                }
                if ($col_content == 'order_type') {
                    $value = $order_type_list[$v['type']];
                }
                if ($col_content == 'progress') {
                    $value = $order_progress[$v['progress']];
                }
                if ($col_content == 'number') {
                    $value = $k + 1;
                }
                if ($col_content == 'cinema_name') {
                    $user_role_id = user_helper::get_user_role_id($v['user_id']);
                    if ($user_role_id == user_config::STORE_MANAGER || $user_role_id == user_config::STORE_OWNER) {
                        $store_info = store_helper::get_store($v['store_id']);
                        $cinema_info = cinema_helper::get_cinema_info_by_id($store_info['zzb_id']);
                        if ($cinema_info) {
                            $value = $cinema_info['cinema_name'];
                        } else {
                            $value = $store_info['title'];
                        }
                    }
                }
                if ($col_content == 'agency') {
                    $user_info = user_helper::get_user_info($v['agency_id']);
                    $value = $user_info['realname'];
                }
                if ($col_content == 'agency_mobile') {
                    $user_info = user_helper::get_user_info($v['agency_id']);
                    $value = $user_info['mobile'];
                }
                if ($col_content == 'cinema_id') {
                    $value = $v['store_id'];
                }
                if ($col_content == 'province') {
                    $province_info = area_helper::get_area_info($store_info['province_id']);
                    if ($province_info) {
                        $value = $province_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['province'];
                        }
                    }
                }
                if ($col_content == 'city') {
                    $city_info = area_helper::get_area_info($store_info['city_id']);
                    if ($city_info) {
                        $value = $city_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['city'];
                        }
                    }
                }
                if ($col_content == 'county') {
                    $county_info = area_helper::get_area_info($store_info['district_id']);
                    if ($county_info) {
                        $value = $county_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['county'];
                        }
                    }
                }

                $objActSheet->setCellValue($place, $value);
            }


            foreach ($v['order_relation'] as $r_k => $order_relation_info) {

                $one_goods_id = $order_relation_info['goods_id'];
                $one_goods_price = array(
                    $order_relation_info['goods_price'],
                    $order_relation_info['real_price'],
                    $order_relation_info['goods_num']
                );
                foreach ($attach_row as $kt => $vt) {

                    if (isset($goods_detail[$one_goods_id][$kt])) {
                        if (is_array($goods_detail[$one_goods_id][$kt])) {
                            $row_id = $goods_detail[$one_goods_id][$kt][0];
                        } else {
                            $row_id = $goods_detail[$one_goods_id][$kt];
                        }
                    }

                    $objActSheet->setCellValue($row_id . $key, $one_goods_price[$kt]);
                }
            }
            $key++;
        }

        //设置页面类型
        header("Content-Type: application/vnd.ms-excel");
        //用于下载的文件头
        header("Content-Type: application/force-download");
        header("Content-Type: application/download");
        header("Content-Type: application/octet-stream");

        //$title = trim($catebirthday_gift_recordry_name."表").".xls";
        $title = date('Y-m-d') . "影院订单明细.xls";
        // ff正常，ie不正常，下面是从网站找到的解决方案
        if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
            $title = rawurlencode($title);
        }
        header("Content-Disposition: attachment; filename=" . $title);
        header("Content-Transfer-Encoding: binary");
        //最后修改时间
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        //不使用缓存
        header('Cache-Control: ust-revalidate, post-check=0, pre-check=0');
        header('Cache-Control: public');
        header("Expires: 0");
        header("Pragma: public");
        $objWriter->save('php://output');
        exit;
    }

    public function export_excel2($list = array()) {
        //初始化excel对象
        $objPHPExcel = new PHPExcel();
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        //设置当前的sheet索引，用于后续的内容操纵
        $objPHPExcel->setActiveSheetIndex(0);
        $objActSheet = $objPHPExcel->getActiveSheet();
        // 哪几列
        $col_arr = array(
            'A',
            'B',
            'C',
            'D',
            'E',
            'F',
            'G',
            'H',
            'I',
            'J',
            'K',
            'L',
            'M',
            'N',
            'O',
            'P',
            'Q',
            'R',
            'S',
            'T'
        );
        // 第一排的标题
        $col_title_arr = array(
            '序号',
            '订单编号',
            '商品名称',
            '单价',
            '实际支付',
            '商品数量',
            '总数量',
            '总价',
            '商家信息',
            '杯型信息(杯)',
            '订单类型',
            '订单状态',
            '支付方式',
            '影院名称',
            '影院id',
            '省',
            '市',
            '区',
            '合伙人',
            '合伙人手机'
        );
        $col_content_arr = array(
            'number',
            'order_id',
            'goods_title',
            'goods_price',
            'real_price',
            'goods_num',
            'sum',
            'price',
            'store_info',
            'cup_info',
            'order_type',
            'progress',
            'pay_type',
            'cinema_name',
            'cinema_id',
            'province',
            'city',
            'county',
            'agency',
            'agency_mobile'
        );
        // 设置文档属性
        foreach ($col_arr as $k => $v) {
            //设置4个列的宽度
            if (in_array($v, array('A'))) {
                $objActSheet->getColumnDimension($v)->setWidth(8);
            } else {
                $objActSheet->getColumnDimension($v)->setWidth(20);
            }
            //设置单位格内容A1,B1,C1,D1
            $objActSheet->setCellValue($v . "1", $col_title_arr[$k]);
            //格式化数字为字符串，避免导致数字默认右对齐单元格
            $objActSheet->getStyle($v)->getNumberFormat()->setFormatCode("@");
            //设置自动换行
            $objActSheet->getStyle($v)->getAlignment()->setWrapText(true);
        }

        // 填充单元格
        $key = 2;
        $mergeArr = array('A', 'B', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T');
        foreach ($list as $k => $v) {
            $mergeCells = count($v['order_relation']);
            if ($mergeCells > 1) {
                $objActSheet->mergeCells('A' . $key . ':A' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('B' . $key . ':B' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('G' . $key . ':G' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('H' . $key . ':H' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('I' . $key . ':I' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('J' . $key . ':J' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('K' . $key . ':K' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('L' . $key . ':L' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('M' . $key . ':M' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('N' . $key . ':N' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('O' . $key . ':O' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('P' . $key . ':P' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('Q' . $key . ':Q' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('R' . $key . ':R' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('S' . $key . ':S' . ($key + $mergeCells - 1));
                $objActSheet->mergeCells('T' . $key . ':T' . ($key + $mergeCells - 1));
            }

            $order_type_list = order_config::$order_type;
            $cup_name_list = cup_config::$cup_type;
            $pay_type_list = order_config::$pay_type;
            $order_progress = order_config::$store_progress;
            $store_info = store_helper::get_store($v['store_id']);
            // 先将合并的信息填入excl
            foreach ($col_arr as $k2 => $v2) {
                $place = $v2 . $key;
                $col_content = $col_content_arr[$k2];
                if (!in_array($v2, $mergeArr)) {
                    continue;
                }

                $zzb_info = array();
                if ($store_info['zzb_id'] > 0) {
                    $zzb_info = cinema_helper::get_cinema_info_by_id($store_info['zzb_id']);
                }

                $value = '';
                if ($col_content == 'order_id') {
                    $value = ' ' . order_helper::order_id_encode($v['id']);
                } elseif ($col_content == 'price') {
                    $value = ' ' . $v['price'];
                } elseif ($col_content == 'pay_type') {
                    $value = $pay_type_list[$v['pay_type']];
                } elseif ($col_content == 'sum') {
                    //订单总商品数
                    $value = ' ' . $v['goods_num'];
                } elseif ($col_content == 'store_info') {
                    // 商家信息
                    $user_info = user_helper::get_user_info($v['user_id']);
                    // 田鹏说删掉手机号 2016-11-15
                    $value = $user_info['realname'];
                    // $value = "收货人：" . $user_info['realname'] . "\r手机号码：" . $user_info['mobile'];
                } elseif ($col_content == 'cup_info') {
                    // 杯型信息
                    $cup_list_info = cup_helper::get_order_cup_data($v['id']);
                    if (!$cup_list_info) {
                        $value = '没有散装商品';
                    } else {
                        $value = '';
                        foreach ($cup_list_info as $cup_k => $cup_v) {
                            $value .= $cup_name_list[$cup_v['cup_type']] . '：' . $cup_v['true_cup_num'] . "\r";
                        }
                    }
                } elseif ($col_content == 'order_type') {
                    $value = $order_type_list[$v['type']];
                } elseif ($col_content == 'progress') {
                    $value = $order_progress[$v['progress']];
                } elseif ($col_content == 'number') {
                    $value = $k + 1;
                } elseif ($col_content == 'cinema_name') {
                    $user_role_id = user_helper::get_user_role_id($v['user_id']);
                    if ($user_role_id == user_config::STORE_MANAGER || $user_role_id == user_config::STORE_OWNER) {
                        $store_info = store_helper::get_store($v['store_id']);
                        $value = $store_info['title'];
                    }
                } elseif ($col_content == 'agency') {
                    $user_info = user_helper::get_user_info($v['agency_id']);
                    $value = $user_info['realname'];
                } elseif ($col_content == 'agency_mobile') {
                    $user_info = user_helper::get_user_info($v['agency_id']);
                    $value = $user_info['mobile'];
                } elseif ($col_content == 'cinema_id') {
                    $value = $v['store_id'];
                } elseif ($col_content == 'province') {
                    $province_info = area_helper::get_area_info($store_info['province_id']);
                    if ($province_info) {
                        $value = $province_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['province'];
                        }
                    }
                } elseif ($col_content == 'city') {
                    $city_info = area_helper::get_area_info($store_info['city_id']);
                    if ($city_info) {
                        $value = $city_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['city'];
                        }
                    }
                } elseif ($col_content == 'county') {
                    $county_info = area_helper::get_area_info($store_info['district_id']);
                    if ($county_info) {
                        $value = $county_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['county'];
                        }
                    }
                }


                $objActSheet->setCellValue($place, $value);
            }
            foreach ($v['order_relation'] as $r_k => $order_relation_info) {
                $num = $key + $r_k;
                $goods_info = goods_helper::get_goods_info($order_relation_info['goods_id']);
                $goods_title = $goods_info['title'];
                $goods_price = $order_relation_info['goods_price'];
                $goods_num = $order_relation_info['goods_num'];
                $real_price = $order_relation_info['real_price'];
                $objActSheet->setCellValue('C' . $num, $goods_title);
                $objActSheet->setCellValue('D' . $num, ' ' . $goods_price);
                $objActSheet->setCellValue('E' . $num, $real_price);
                $objActSheet->setCellValue('F' . $num, $goods_num);
            }

            if ($mergeCells > 1) {
                $key += $mergeCells;
            } else {
                $key++;
            }
        }

        //设置页面类型
        header("Content-Type: application/vnd.ms-excel");
        //用于下载的文件头
        header("Content-Type: application/force-download");
        header("Content-Type: application/download");
        header("Content-Type: application/octet-stream");

        //$title = trim($catebirthday_gift_recordry_name."表").".xls";
        $title = date('Y-m-d') . "影院订单汇总.xls";
        // ff正常，ie不正常，下面是从网站找到的解决方案
        if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
            $title = rawurlencode($title);
        }
        header("Content-Disposition: attachment; filename=" . $title);
        header("Content-Transfer-Encoding: binary");
        //最后修改时间
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        //不使用缓存
        header('Cache-Control: ust-revalidate, post-check=0, pre-check=0');
        header('Cache-Control: public');
        header("Expires: 0");
        header("Pragma: public");
        $objWriter->save('php://output');
        exit;
    }
}